import datetime
import time


# 装饰器：打印任何函数的执行时间
def execution_time(func):
    def wrapper(*args, **kwargs):
        start_datetime = datetime.datetime.now()
        print(f" 函数 {func.__name__} 开始执行时间: {start_datetime.strftime('%Y-%m-%d %H:%M:%S')}")
        # 执行原函数
        result = func(*args, **kwargs)
    return wrapper


# 使用装饰器测试不同的函数

@execution_time
def say_hello():
    print('hello\n')


@execution_time
def say_hello_with_name(name):
    print(f'hello {name}')
    time.sleep(0.3)
    return f"Greeted {name}"

if __name__ == '__main__':
    # 测试各种函数
    say_hello()
    # result1 = say_hello_with_name("Alice")
    say_hello_with_name("Alice")